// wtkbase.hpp
//

#ifndef _WTKBASE_HPP
#define _WTKBASE_HPP

#include <wgl/wgl.hpp>
#include <wgl/wgl_gl.hpp>


#include <cassert>
#include <type_traits>
#include <memory>
#include <bitset>
#include <filesystem>
#include <string>
#include <functional>
#include <list>
#include <unordered_set>
#include <unordered_map>

#ifdef _WIN32
#  ifdef WTK_COMPILE
#    define WTK_API __declspec(dllexport)
#  else
#    define WTK_API __declspec(dllimport)
#  endif
#else
#  define WTK_API
#endif


#define WTK_ENUM_VALUE(v) (static_cast<std::underlying_type<decltype(v)>::type>(v))


// [FIXME] logging
#include <stdio.h>

#define WTK_LOG(f, lvl, msg...) do {            \
    fprintf((f), "wtk:%s:%d:%s ",               \
            __FILE__, __LINE__, (lvl));         \
    fprintf((f), msg);                          \
    fprintf((f), "\n");                         \
  } while (0)

#define WTK_TRACE(msg...) WTK_LOG(stdout, "", msg)

#define WTK_WARNING(msg...) WTK_LOG(stderr, "WARNING:", msg)

#define WTK_ERROR(msg...) WTK_LOG(stderr, "ERROR:", msg)

#define WTK_FATAL(msg...) do {                  \
    WTK_ERROR(msg);                             \
    abort();                                    \
  } while (0)

#define WTK_ASSERT(expr) do {                       \
    if (!(expr)) {                                  \
      WTK_FATAL("ASSERTION FAILED: `" #expr "'");   \
    }                                               \
  } while (0)

#endif
